<template>
  <el-button type="primary" @click="add">录入线索</el-button>
  <el-button type="success" @click="importExcel">导入线索</el-button>
  <el-button type="danger">批量删除</el-button>
  <el-table :data="tableData" style="width: 100%">
    <el-table-column type="selection" width="55" />
    <el-table-column property="id" label="序号" width="80" />
    <el-table-column property="owner" label="负责人" width="80" />
    <el-table-column property="activity" label="所属活动" width="130" />
    <el-table-column property="fullName" label="姓名" width="100" />
    <el-table-column property="gender" label="称呼" width="100" />
    <el-table-column property="phone" label="手机" width="120" />
    <el-table-column property="weixin" label="微信" width="120" />
    <el-table-column property="isNeed" label="是否贷款" width="80" />
    <el-table-column property="inclinationStatus" label="意向状态" width="80" />
    <el-table-column property="inclinationProduct" label="意向产品" width="100" />
    <el-table-column property="status" label="线索状态" width="100" />
    <el-table-column property="clueSource" label="线索来源" width="80" />
    <el-table-column property="nextContactTime" label="下次联系时间" width="120" />
    <el-table-column label="操作" width="140">
      <template #default="scoped">
        <el-button link type="primary" size="small" @click="detail(scoped.row)">详情</el-button>
        <el-button link type="primary" size="small" @click="edit(scoped.row)">编辑</el-button>
        <el-button link type="primary" size="small" @click="del(scoped.row.id)">删除</el-button>
      </template>
    </el-table-column>
  </el-table>
  <el-pagination background layout="prev, pager, next" :total="total" :page-size="pagesize" @current-change="change" />
  <el-dialog v-model="dialogTableVisible" title="上传文件" width="800">
    <el-upload ref="uploadRef" class="upload-demo"
      :auto-upload="false" accept=".xlsx" :http-request="upload">
      <template #trigger>
        <el-button type="primary">选择文件</el-button>
      </template>

      <el-button class="ml-3" type="success" @click="submitUpload">
        上传文件
      </el-button>

      <template #tip>
        <div class="el-upload__tip">
         只能上传xsl,xsls文件
        </div>
      </template>
    </el-upload>
  </el-dialog>
</template>
<script setup>
import { useCounterStore } from '@/stores/counter';
import { doGet, doPost } from '@/util/axios';
import { notify } from '@/util/notification';
import { onMounted, ref } from 'vue';
import { useRouter } from 'vue-router';
let store=useCounterStore()
let Router=useRouter()
const dialogTableVisible = ref(false)
let tableData=ref([])
let current=ref(1)
const pagesize=10
let total=ref(0)
onMounted(()=>{
    change(current.value)
})
function change(num){
    getList(num)
}
function getList(num){
  doGet("/getClueList",{"current":num,"pagesize":pagesize}).then(res=>{
    tableData.value=res.data.data.list
    console.log(res)
    current.value=res.data.data.pageNum
    total.value=res.data.data.total
  })
}
function importExcel(){
  dialogTableVisible.value=true
}
const uploadRef = ref()
const submitUpload = () => {
  uploadRef.value.submit()
}
function upload(options){
  let query={}
  query[options.filename]=options.file
  doPost("/importClueExcel",query,{
    "Content-Type":" multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW",
  }).then(res=>{
    if(res.data.code==200){
      notify("上传成功","success")
      uploadRef.value.clearFiles()
      dialogTableVisible.value=false
    }else{
      notify("上传失败","error")
    }
  })
}
function add(){
 Router.push({name:"ClueAdd"})
}
function edit(user){
  console.log(user)
  // store.setData(user)
  // Router.push({name:"ClueEdit",params:{id:user.id}})
}
</script>
<style scoped></style>